package com.xingshentech.ugv.operate.base;

import com.google.gson.Gson;
import com.xingshentech.ugv.operate.module.bean2.UserBean;
import com.xingshentech.ugv.operate.module.constant.Constants;
import com.xingshentech.ugv.operate.module.utils.SharedPreferencesUtils;
import com.xingshentech.ugv.operate.sdk.SDKAdapter;

public class UserUtil {
    public static void setAccessToken(String accessToken) {
        SharedPreferencesUtils.setParam(Constants.accessToken, accessToken);
    }

    public static String getAccessToken() {
        return (String) SharedPreferencesUtils.getParam(Constants.accessToken, "");
    }
    /**
     * 缓存域名
     */

    public static void setDomin(String domin) {
        SharedPreferencesUtils.setParam("DOMIN", domin);
    }

    /**
     * 缓存域名端口
     */

    public static void setDominPort(int port) {
        SharedPreferencesUtils.setParam("DOMIN_PORT", port);
    }

    /**
     * 获取域名
     */
    public static String getDomin() {
        return (String) SharedPreferencesUtils.getParam("DOMIN", SDKAdapter.address);
    }

    /**
     * 获取域名端口
     */
    public static int getDominPort() {
        return (int) SharedPreferencesUtils.getParam("DOMIN_PORT", SDKAdapter.port);
    }

    public static void setUserBean(UserBean userBean) {
        SharedPreferencesUtils.setParam(Constants.userData, new Gson().toJson(userBean));
    }

    public static UserBean getUserBean() {
        String user = (String) SharedPreferencesUtils.getParam(Constants.userData, "");
        if (user != null && !user.equals("")) {
            return new Gson().fromJson(user, UserBean.class);
        } else {
            return new UserBean();
        }
    }
}
